/*
  侧边栏
 */

import 'package:flutter/material.dart';

void main() => runApp(MyApp());

class MyApp extends StatelessWidget {
  @override
  Widget build(BuildContext context) {
    return MaterialApp(
      home: MyDrawer(),
    );
  }
}

class MyDrawer extends StatefulWidget {
  @override
  _MyDrawerState createState() => _MyDrawerState();
}

class _MyDrawerState extends State<MyDrawer> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(title: Text('Drawer'),),
      // 左侧边栏
      drawer: Drawer(
        child: ListView(
          children: [
            // 左侧边栏
            DrawerHeader(
                child: CircleAvatar(
                  child: Image.asset('mg.jpg'),
                )
            ),
            ListTile(
              title: Text('通用'),
              subtitle: Text('缓存、证书等'),
            ),
            ListTile(
              leading: Icon(Icons.wifi),
              title: Text('网络'),
              trailing: Icon(Icons.keyboard_arrow_right),
            ),
            ListTile(
              title: Text('关闭'),
              onTap: (){
                // 关闭侧边栏
                Navigator.of(context).pop();
              },
            )
          ],
        ),
      ),
      // 右侧边栏
      endDrawer: Drawer(
        child: ListView(
          children: [
            // 用户名头部
            UserAccountsDrawerHeader(accountName: Text('看着我别说话'), accountEmail: Text('18673298768@163.com')),
            ListTile(
              title: Text('通用'),
              subtitle: Text('缓存、证书等'),
            ),
            ListTile(
              leading: Icon(Icons.wifi),
              title: Text('网络'),
              trailing: Icon(Icons.keyboard_arrow_right),
            ),
          ],
        ),
      ),
      body: Center(
        child: TextButton(
          child: Text('打开左侧边栏'),
          onPressed: (){
            // 打开侧边栏，暂时会报错
            Scaffold.of(context).openDrawer();
          },
        ),
      ),
    );
  }
}

